/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package vn.ugame.module;

import vn.ugame.model.bl.ModuleManager;
import vn.ugame.module.store.ImageModule;
import vn.ugame.module.store.StoreModule;

/**
 *
 * @author Namtp
 */
public class ModuleFactory {

    private static ModuleFactory instance;

    public static ModuleFactory createModuleFactory() {
        if (instance == null) {
            instance = new ModuleFactory();
        }
        return instance;
    }

    private ModuleFactory() {
    }

    public Module createModule(String name) {
        ModuleManager manager = new ModuleManager(null);
        vn.ugame.model.entity.Module moduleInfo = manager.findModuleByName(name);
        if (moduleInfo != null) {
            if(moduleInfo.getType().equals(ModuleType.STORE_ALL)
                    ||moduleInfo.getType().equals(ModuleType.STORE_SPECIFIC)
                    ||moduleInfo.getType().equals(ModuleType.STORE_FILTER)){
                
                Module module = new StoreModule();
                module.init(moduleInfo);
                return module;                
            }else if(moduleInfo.getType().equals(ModuleType.IMAGE)){
                Module module = new ImageModule();
                module.init(moduleInfo);
                return module;        
            }
        }
        return null;
    }
}
